package com.ie.sevice.admin;

import com.ie.entity.OrdersEntity;
import com.ie.mapper.admin.OrdersMapper;
import com.ie.sevice.admin.OrdersService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrdersServiceImpl implements OrdersService {

    @Autowired
    private OrdersMapper ordersMapper;

    @Override
    public Map<String, Object> getOrdersByUidWithPage(Integer uid, Integer pageNum, Integer pageSize) {
        // 创建分页对象
        IPage<OrdersEntity> page = new Page<>(pageNum, pageSize);

        // 构建查询条件：根据用户ID筛选
        LambdaQueryWrapper<OrdersEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OrdersEntity::getBusertableId, uid); // 使用实体类字段名

        // 执行分页查询
        ordersMapper.selectPage(page, queryWrapper);

        // 封装结果到 Map
        Map<String, Object> result = new HashMap<>();
        result.put("ordersByUid", page.getRecords());     // 当前页数据
        result.put("totalPage", page.getPages());         // 总页数
        result.put("total", page.getTotal());             // 总记录数
        result.put("current", page.getCurrent());         // 当前页码
        result.put("size", page.getSize());               // 每页数量

        return result;
    }
}